package com.qf.controller;

import com.qf.config.SystemConfig;
import com.qf.entity.User;
import com.qf.param.*;
import com.qf.service.UserService;

import com.qf.vo.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;


/**
 * 用户表(User)表控制层

 */
@RestController
@RequestMapping("user")
@Tag(name = "用户模块")
public class UserController {
    /**
     * 服务对象
     */
    @Resource
    private UserService userService;

    @Operation(summary = "用户注册")
    @PostMapping("/register")
    public R login(@RequestBody UserRegister userRegister){
        return userService.register(userRegister);
    }

    @Operation(summary = "用户登录")
    @PostMapping("/login")
    public R login(@RequestBody UserLogin userLogin){
        return userService.login(userLogin);
    }

    @Operation(summary = "发送手机号登录验证码")
    @PostMapping("/sendcode")
    public R sendCode(String phone){
        return userService.sendCode(phone);
    }

    @Operation(summary = "校验手机号登录验证码")
    @PostMapping("/logincode")
    public R loginCode(@RequestBody UserLoginCode code){
        return userService.loginCode(code);
    }

    @Operation(summary = "修改密码")
    @PostMapping("/updatepass")
    public R updatePass(@RequestBody Map<String,String> map, HttpServletRequest request){
        return userService.updatePass(map.get("password"),request.getHeader(SystemConfig.HEADER_TOKEN));
    }

    @Operation(summary = "发送密码找回验证码")
    @PostMapping("/sendfcode")
    public R sendCodeFindPass(String phone){
        return userService.sendCodeFindPass(phone);
    }

    @Operation(summary = "找回密码")
    @PostMapping("/findpass")
    public R findPass(@RequestBody UserFind userFind){
        return userService.findPass(userFind);
    }

    @Operation(summary = "修改个人信息")
    @PostMapping("/updateinfo")
    public R updateInfo(@RequestBody UserUpate userUpate, HttpServletRequest request){
        return userService.updateInfo(userUpate,request.getHeader(SystemConfig.HEADER_TOKEN));
    }
}

